import Vue from 'vue'
// 引入vue-router
import VueRouter from 'vue-router'

// 重复跳转的解决方法
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
//   return originalPush.call(this, location).catch(err => err)
// }

// 使用路由
Vue.use(VueRouter)

// 定义路由组件
// import Home from '../views/Home.vue'
// 定义路由
const routes = [ // 路由信息，路径，组件
    { // 重定向 解决一些问题
        path: '/', 
        redirect: '/home',
    },
    {
        path: '/home',
        // component: Home
        // 动态加载，异步组件
        component: () => import('@/views/Home.vue'),
        // alias: '/', // 别名
    },
    {
        path: '/learn',
        component: () => import('@/views/Learn.vue')
    },
    {
        path: '/student',
        component: () => import('@/views/Student.vue')
    },
    {
        path: '/about',
        component: () => import('@/views/About.vue')
    },
    {
        path: '/activity',
        component: () => import('@/views/Activity.vue'),
        redirect: '/activity/academic', // 重定向
        children: [ // 嵌套路由
            // { // 临时解决跳转过来内容为空的情况
            //     path: '',
            //     component: () => import('../views/ActivityChilds/Academic.vue')
            // },
            {
                path: 'academic',
                name: 'academic',
                component: () => import('@/views/ActivityChilds/Academic.vue')
            },
            {
                path: 'personal',
                name: 'personal',
                component: () => import('@/views/ActivityChilds/Personal.vue')
            },
            {
                path: 'download',
                name: 'download',
                component: () => import('@/views/ActivityChilds/Download.vue')
            },
            {
                path: 'vuexstore',
                name: 'vuexstore',
                component: () => import('../views/ActivityChilds/VuexStore.vue')
            }
        ]
    },
    { // 错误页面
        path: '/error',
        name: 'error',
        component: () => import('@/components/Error.vue')
    },
    { // 输入的页面不存在跳转至指定的页面
        path: '*',
        redirect: '/error',
    }
]
// 创建router实例，能后传router配置。VueRouter是一个构造函数
const router = new VueRouter({
    mode: 'history', // history 模式
    base: '/',
    routes, // 配置
});

// 导出路由配置
export default router